let dataSource = {
    突发事件: new Cesium.CustomDataSource("突发事件"),
    生产安全事故: new Cesium.CustomDataSource("生产安全事故"),
    历史火灾: new Cesium.CustomDataSource("历史火灾"),
};
const image = {
    突发事件: "./images/sjzx/icons/突发事件.png",
    生产安全事故: "./images/sjzx/icons/生产安全事故.png",
    历史火灾: "./images/sjzx/icons/森林火情.png",
};

function createPoint(pointType, pointData, kbApiDetail, eventType, event) {
    if (!viewer.dataSources.contains(dataSource[pointType])) {
        viewer.dataSources.add(dataSource[pointType]);
    }
    let entities = dataSource[pointType].entities;
    pointData.forEach(point => {
        // 更新数据时使用
        // let entity = entities.getById(car.vehicleno10000034);
        // if (entity) {
        //     entity.position = Cesium.Cartesian3.fromDegrees(Number(car.lon00306599), Number(car.lat00306598), 0);
        // } else {
        let x = null;
        let y = null;
        if (point.lon && point.lat) {
            x = point.lon;
            y = point.lat;
        } else if (point.lng && point.lat) {
            x = point.lng;
            y = point.lat;
        } else if (point.jd && point.wd) {
            x = point.jd;
            y = point.wd;
        }
        //1，市，2。县区，3，乡镇街道 3，村
        let labelDistance = {
            "3": [30000, 18000],
            "4": [18000, 0],
        };
        //console.log(labelDistance[point.distance][1], labelDistance[point.distance][0])
        let bill = entities.add({
            id: point.id,
            position: Cesium.Cartesian3.fromDegrees(Number(x), Number(y), 0),
            billboard: {
                image: image[pointType], // default: undefined
                horizontalOrigin: Cesium.HorizontalOrigin.CENTER, // default
                verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // default: CENTER
                // color : Cesium.Color.LIME, // default: WHITE
                width: 40,
                height: 40,
                scaleByDistance: new Cesium.NearFarScalar(
                    100000,
                    1,
                    1000000,
                    0.5
                ),
            },
            label: {
                text: point.name ? point.name : point.charge,
                show: true,
                font: "15pt Source Han Sans CN", //字体样式
                fillColor: Cesium.Color.LAWNGREEN, //字体颜色
                outlineColor: Cesium.LabelStyle.BLACK,
                style: Cesium.LabelStyle.FILL_AND_OUTLINE, //label样式
                outlineWidth: 4,
                // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                verticalOrigin: Cesium.VerticalOrigin.TOP, //垂直位置
                horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //水平位置
                pixelOffset: new Cesium.Cartesian2(0, -10), //偏移
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
                    0,
                    6000
                ),
            },
            type: pointType, //防汛防风类型
            kbApiDetail,
            detail: point,
        });
        //添加点击事件
        if (eventType && event) {
            bill[eventType] = event;
        }
        // }
    });
}
function removePointByType(type) {
    dataSource[type].entities.removeAll();
}
function removeAllPoint() {
    for (let key in dataSource) {
        dataSource[key].entities.removeAll();
    }
}
export default {
    createPoint,
    removePointByType,
    removeAllPoint,
};
